﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class sysadmin_UserManager_AddUserInfo_Export : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string filepath = string.Empty;
        string eror = string.Empty;
        DataTable dt_Excel = new DataTable();
        StringBuilder str_msg = new StringBuilder();
        filepath = @"F:\lms\1defff82-9555-4e06-9151-ef08f9881ba1.xls";
        try
        {
            string strConn;
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";


            OleDbConnection conn = new OleDbConnection(strConn);
            string st = conn.State.ToString();
            string s = conn.Site.Component.ToString();
            //conn.State
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            DataTable sheetNames = conn.GetOleDbSchemaTable
            (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
            if (sheetNames.Rows.Count > 0)
            {
                string sqlcmd = "select * from [" + sheetNames.Rows[0]["TABLE_NAME"].ToString() + "]";
                DataSet ds = new DataSet();
                OleDbDataAdapter objda = new OleDbDataAdapter(sqlcmd, conn);
                objda.Fill(ds);
                dt_Excel = ds.Tables[0];
            }

            eror = str_msg.ToString();
        }
        //catch (OleDbException e)
        //{
        //    eror += e.Message;
        //}
        catch (Exception ex)
        {

            eror = "错误信息：" + ex.Message + "  TargetSite:" + ex.TargetSite + "   InnerException:" + ex.InnerException + "   Source:" + ex.Source;
        }
        lab_msg.Text = eror;
     //   return dt_Excel;
    }
    protected void btn_DownLoad_Click(object sender, EventArgs e)
    {

    }
}
